package exam.bak.tencent;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class P1 {
    public static void main(String[] args) {
        /*Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        while (N-- > 0) {
            System.out.println(solve(scanner.nextInt()));
        }*/
        System.out.println(solve(1000));
    }

    public static Set<Integer> compute(int n, int x) {
        Set<Integer> list = new TreeSet<>();
        for (int i = 1; i * i < n; i++) {
            if (n % i == 0) {
                for (int num : list) {
                    if (Math.abs(num - i) < x) {
                        list.clear();
                        return list;
                    }
                }

                list.add(i);
                if (i != n / i) {
                    list.add(n / i);
                }
            }
        }
        return list;
    }

    public static int solve(int x) {
        int num = 5;
        label:
        while (true) {
            num++;
            Set<Integer> factorSet = compute(num, x);
            if (factorSet.size() < 4) {
                continue;
            }
            Iterator<Integer> iterator = factorSet.iterator();
            int tmp = iterator.next();
            while (iterator.hasNext()) {
                int n = iterator.next();
                if (n - tmp < x) {
                    continue label;
                }
                tmp = n;
            }
            return num;
        }
    }

    public static int solve1(int x) {
        int num = 6;
        while (true) {
            int tmp = 1;
            int count = 1;
            for (int i = 2; i <= num; i++) {
                if (num % i == 0) {
                    count++;
                    if (i - tmp < x) {
                        break;
                    } else {
                        tmp = i;
                    }
                    if (i == num && count >= 4) {
                        return num;
                    }
                }
            }
            num++;
        }
    }


}
